package com.ctsi.security.event.organ;

import com.ctsi.commons.event.AbstractObserver;
import com.ctsi.commons.event.BaseEvent;
import com.ctsi.organise.common.model.Organise;
import com.ctsi.security.manager.impl.DepartAdminFetchObjIds;
import com.ctsi.security.manager.impl.DishiAdminFetchObjIds;
import com.ctsi.security.manager.impl.OrganFetchObjIds;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;


public class UpdateOrganiseEventHandle extends AbstractObserver {
	private static Logger logger = LoggerFactory.getLogger(UpdateOrganiseEventHandle.class);

	@Override
	public void onEvent(Object[] args) {
		BaseEvent event = (BaseEvent) args[0];// 得到事件
		// 获得事件源
		Organise organ = (Organise) event.getSource();

		/*
		 * 处理当组织更新时，如果组织的数据对象ID发生变化，其下属人员的数据对象也要随之发生变化
		 */
		if (args.length > 1) {
			// 查看是否数据对象改变
			Organise oldOrgan = (Organise) args[1];
			if (organ != null && oldOrgan != null && !organ.getPartyTypeId().equals(oldOrgan.getPartyTypeId())) {
				OrganFetchObjIds.removeCache(null);
				DishiAdminFetchObjIds.removeCache(null);
				DepartAdminFetchObjIds.removeCache(null);
				// OrganFetchObjIds.removeCacheByDataObjectId(organ.getPartyid());

			} else {
				if (organ != null) {
					logger.info("不处理组织 {}", organ.getPartyName());
				}
			}
		}

	}

}
